package com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import com.dao.IUserDao;
import com.model.User;
import com.service.IUserService;

public class UserServiceImpl implements IUserService {
	
	private IUserDao userDao;
	
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public User login(User user) {
		String hql="from User u where u.username=:username and u.password=:password";
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("username", user.getUsername());
		params.put("password", user.getPassword());
		User u=userDao.get(hql, params);
		return u==null?null:u;
	}

	@Override
	public void save(User o) {
		userDao.save(o);
		
	}

	@Override
	public void delete(Integer id) {
		userDao.delete(id);
	}

	@Override
	public void update(User o) {
		userDao.update(o);
	}

	@Override
	public void saveOrUpdate(User o) {
		userDao.saveOrUpdate(o);
	}

	@Override
	public User get(Integer id) {
		return userDao.get(id);
	}

	@Override
	public List<User> getAll() {
		return userDao.getAll();
	}

	@Override
	public List<User> getAll(String hql) {
		return userDao.getAll(hql);
	}

	@Override
	public List<User> getAll(String hql, int page, int rows) {
		return userDao.getAll(hql, page, rows);
	}

	@Override
	public int count(String hql) {
		return userDao.count(hql);
	}
}
